package 力扣日常刷题.木22二月.第10天216;

/**
 * @author 帅小伙
 * @date 2022/2/16
 * @description
 */
public class Demo70连续子数组的最大和 {


    public int maxSubArray(int[] nums) {
        int ans = nums[0];
        int[] dp = new int[nums.length];
        dp[0] = nums[0];
        for (int i = 1; i < nums.length; i++) {
            dp[i] = Math.max(nums[i], dp[i - 1] + nums[i]);
            ans = Math.max(ans, dp[i]);
        }
        return ans;
    }

}
